﻿using InternetSpiderLib;
using System;
using System.Collections.Generic;
using System.Text;

namespace WeChatGZHTextExtractor.BusinessCreaters
{
    /// <summary>
    /// 监控的Url
    /// </summary>
    public class BC_MonitoringUrl : IBusinessCreater
    {
        private SceneManager _SceneManager;

        public BC_MonitoringUrl()
        {
            _SceneManager = SingleCase.Get<SceneManager>();
        }

        public Action Create()
        {
            if (!UrlMonitoringQueue.GetInstance().TryPop(out DataBox data))
                return null;

            return () =>
            {
                var url = data.Get<string>(PublicKey.HtmlInfo.URL);

                LogHelper.GetInstance().Log(LogType.Info, url);

                var body = HttpHelper.HttpGet(url);

                _SceneManager.TriggerScene(new DataBox(data)
                    .Set<string>(PublicKey.EventType.EVENT_NAME, PublicKey.EventType.HTTP_GET)
                    .Set<string>(PublicKey.HtmlInfo.BODY, body));
            };
        }
    }
}
